package com.wowoai.wallpaper.controller;

import com.wowoai.common.userInfo.UserInfo;
import com.wowoai.common.page.Pagination;
import com.wowoai.common.response.ResponseVO;
import com.wowoai.wallpaper.controller.req.WallpaperReq;
import com.wowoai.wallpaper.controller.vo.WallpaperVO;
import com.wowoai.wallpaper.convert.WallpaperConvert;
import com.wowoai.wallpaper.service.WallpaperServiceI;
import com.wowoai.wallpaper.service.dto.WallpaperDTO;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/wallpaper")
public class WallpaperController {

    private final WallpaperServiceI wallpaperServiceI;

    public WallpaperController(WallpaperServiceI wallpaperServiceI) {
        Assert.notNull(wallpaperServiceI,"wallpaperServiceI 不能为空");
        this.wallpaperServiceI = wallpaperServiceI;
    }

    /**
     * 分页查询壁纸列表
     * @param wallpaperReq
     * @return
     */
    @PostMapping("/getWallpaperList")
    public ResponseVO< Pagination<WallpaperVO>> getWallpaperList(@RequestBody WallpaperReq wallpaperReq){
        Pagination<WallpaperDTO> wallpaperDTOPagination = wallpaperServiceI.getWallpaperList(wallpaperReq.getPageNum(), wallpaperReq.getPageSize());
        List<WallpaperVO> wallpaperVOS = WallpaperConvert.INS.dto2VO(wallpaperDTOPagination.getList());
        Pagination<WallpaperVO> wallpaperVoPagination = new Pagination<>(wallpaperDTOPagination.getPageNum(),wallpaperDTOPagination.getPageSize(),
                wallpaperDTOPagination.getTotalCount(), wallpaperVOS);
        return ResponseVO.success(wallpaperVoPagination);
    }

    /**
     * 上传壁纸
     * @param files
     * @return
     */
    @PostMapping("uploadFile")
    public ResponseVO<Void> uploadFile(@RequestParam("file") MultipartFile file){
        UserInfo userInfo = new UserInfo();
//        List<MultipartFile> multipartFiles = files.getFiles();
        userInfo.setUserId(123L);
        userInfo.setUserName("admin");
        wallpaperServiceI.uploadFile(userInfo,file);
        return ResponseVO.success(null);
    }
}
